<template>
  <card title="商品分类">
    <y-table-full 
      v-bind="fullOptions"
      ref="$productCategroy"
      @add="addHandler"
      @edit="editHandler"
      @delete="deleteHandler"
      @load="searchHandler"
      @search="searchHandler"
      ></y-table-full>
  </card>
</template>

<script>
export default {
  data() {
    return {
      fullOptions: {
        // 过滤配置
        filter: [
          { type: "input", field: "keyword", placeholder: "请输入关键字"},
        ],
        // CRUD等配置
        operation: {
          btns: ["add", "edit", "delete"],
          more: ["audit"],
        },
        // 表格配置
        table: {
          columns: [
            { type: "seq", width: 50 },
            { field: "code", title: "编号" },
            { field: "name", title: "属性名称" },
          ],
          data: [],
        },
      },
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
        this.searchHandler()
    },
    /**
     * 添加
     */
    addHandler(event,next) {
      next()
    },
    /**
     * 编辑
     */
    editHandler(event,next) {
      var { api } = this.$refs.$productCategroy
      var select = api.getCurrentRecord();
      if(select){
        next({ keyValue:api.getCurrentRecord().id })
      }else{
        this.$y.notifier.warning('请选中一条记录！')
      }
    },
    /**
     * 删除
     */
    async deleteHandler() {
      var { api } = this.$refs.$productCategroy
      var select = api.getCurrentRecord();
      if(select){
        var { successed } = await this.$y.api.shop.productcategroy.remove(select.id)
        if(successed){
          $y.notifier.success("删除成功！");
          this.searchHandler({})
        }
      }else{
        this.$y.notifier.warning('请选中一条记录！')
      }
    },
    /**
     * 查询
     */
    async searchHandler(params) {
        var { data } = await this.$y.api.shop.productcategroy.getList(params)
        this.fullOptions.table.data = data.items;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>